#!/bin/bash

kubectl create -f nfs.yaml
kubectl create -f object.yaml

# wait for nfs cluster ready
for i in `seq 1 20`
do
  res=$(ceph nfs cluster ls | wc -l)
  if [[ $res != 1 ]]
  then
    sleep 3
  else
    break
  fi
  if [ $i == 20 ]
  then
    echo 'fail to start nfs cluster'
    exit 1
  fi
done

# wait for rgw ready
for i in `seq 1 20`
do
  res=$(kubectl -n rook-ceph get pod -l app=rook-ceph-rgw | grep "2/2" | wc -l)
  if [[ $res != 1 ]]
  then
    sleep 3
  else
    break
  fi
  if [ $i == 20 ]
    then
      echo 'fail to start ceph rgw'
      exit 1
    fi
done

# create dir /volumes/share
ceph fs subvolumegroup create myfs share
ceph nfs export create cephfs my-nfs /var/lib/libvirt/share myfs /volumes/share